package org.wxd.category.spi;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.wxd.common.utils.UUIDGenerator;

import java.io.Serializable;
import java.util.Collections;
import java.util.Map;

/**
 * 类别
 * Created by wangxd on 2015/11/12.
 */
@Document(collection = Category.COLLECTION_NAME)
public class Category implements Serializable {
    public static final long serialVersionUID = 4688774759048818513L;
    public static final String COLLECTION_NAME = "category";
    @Id
    private String id;
    private String name;
    private String parentId;
    private long createTime;
    private Map<String, String> moreInfo;

    Category() {
    }

    public Category(Builder builder) {
        this.id = builder.id;
        this.name = builder.name;
        this.parentId = builder.parentId;
        this.createTime = builder.createTime;
        this.moreInfo = builder.moreInfo;
    }

    public String id() {
        return id;
    }

    public String name() {
        return name;
    }

    public String parentId() {
        return parentId;
    }

    public long createTime() {
        return createTime;
    }

    public Map<String, String> moreInfo() {
        return moreInfo;
    }

    public static Builder newBuilder() {
        return new Builder();
    }

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }

    public static class Builder {
        String id = UUIDGenerator.nextUUID();
        String name;
        String parentId;
        long createTime = System.currentTimeMillis();
        Map<String, String> moreInfo = Collections.EMPTY_MAP;

        public Builder id(String id) {
            this.id = id;
            return this;

        }

        public Builder name(String name) {
            this.name = name;
            return this;

        }

        public Builder parentId(String parentId) {
            this.parentId = parentId;
            return this;
        }

        public Builder createTime(long createTime) {
            this.createTime = createTime;
            return this;
        }

        public Builder moreInfo(Map<String, String> moreInfo) {
            this.moreInfo = moreInfo;
            return this;
        }

        public Category build() {
            return new Category(this);
        }
    }

}
